home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Sprite 1984 - 1993
/
Sprite 1984 - 1993.iso
/
src
/
lib
/
c
/
stdio
/
RCS
/
fread.c,v
< prev
next >
Wrap
Text File
|
1991-12-02
|
4KB
|
147 lines
head 1.2;
branch ;
access ;
symbols sprited:1.2.1;
locks ; strict;
comment @ * @;
1.2
date 91.05.29.16.49.29; author shirriff; state Exp;
branches 1.2.1.1;
next 1.1;
1.1
date 88.06.10.16.23.49; author ouster; state Exp;
branches ;
next ;
1.2.1.1
date 91.12.02.19.57.38; author kupfer; state Exp;
branches ;
next ;
desc
@@
1.2
log
@Changed fread, fwrite to work a chunk at a time instead of a character
at a time.
@
text
@/*
* fread.c --
*
* Source code for the "fread" library procedure.
*
* Copyright 1988 Regents of the University of California
* Permission to use, copy, modify, and distribute this
* software and its documentation for any purpose and without
* fee is hereby granted, provided that the above copyright
* notice appear in all copies. The University of California
* makes no representations about the suitability of this
* software for any purpose. It is provided "as is" without
* express or implied warranty.
*/
#ifndef lint
static char rcsid[] = "$Header: /sprite/src/lib/c/stdio/RCS/fread.c,v 1.1 88/06/10 16:23:49 ouster Exp Locker: shirriff $ SPRITE (Berkeley)";
#endif not lint
#include "stdio.h"
/*
*----------------------------------------------------------------------
*
* fread --
*
* This procedure inputs binary data from a buffered stream.
*
* Results:
* The return value is the number of complete items actually read.
* It may be less than numItems if an end-of-file or error condition
* was encountered; in this case, there may be an additional
* partial item in buf after the complete items.
*
* Side effects:
* Up to numItems*size bytes are read from stream to the memory at
* buf.
*
*----------------------------------------------------------------------
*/
int
fread(bufferPtr, size, numItems, stream)
register char *bufferPtr; /* Place to put the items that are read.
* Must have enough space for numItems*size
* bytes. */
int size; /* Size of each item to be read. */
int numItems; /* Number of items to be read from stream. */
register FILE *stream; /* Stream from which bytes are to be read. */
{
register int num, c, byteCount, itemCount;
for (itemCount = 0; itemCount < numItems; itemCount++) {
for (byteCount = size; byteCount > 0;) {
if (stream->readCount>1) {
num = stream->readCount < byteCount ? stream->readCount
: byteCount;
bcopy(stream->lastAccess+1, bufferPtr, num);
stream->lastAccess += num;
stream->readCount -= num;
byteCount -= num;
bufferPtr += num;
} else {
c = getc(stream);
if (c == EOF) {
return(itemCount);
}
*bufferPtr = c;
bufferPtr++;
byteCount--;
}
}
}
return(numItems);
}
@
1.2.1.1
log
@Initial branch for Sprite server.
@
text
@d17 1
a17 1
static char rcsid[] = "$Header: /sprite/src/lib/c/stdio/RCS/fread.c,v 1.2 91/05/29 16:49:29 shirriff Exp $ SPRITE (Berkeley)";
@
1.1
log
@Initial revision
@
text
@d17 1
a17 1
static char rcsid[] = "$Header: atoi.c,v 1.1 88/04/28 17:20:23 ouster Exp $ SPRITE (Berkeley)";
d51 1
a51 1
register int itemCount, byteCount, c;
d54 19
a72 8
for (byteCount = 0; byteCount < size; byteCount++) {
c = getc(stream);
if (c == EOF) {
return(itemCount);
}
*bufferPtr = c;
bufferPtr++;
}
@